<?php
/****************************************************
 * $Date:: Jun 13, 2010 11:54:00 PM					*
 * $Revision:										*
 * $Author:: duongthienduc							*
 * $Comment::										*
 ****************************************************/

class Bet_Auth_Adapter_DbTable extends Zend_Auth_Adapter_DbTable {

	/**
	 * Customize user's indentity stored in Zend_Auth
	 * @see library/Zend/Auth/Adapter/Zend_Auth_Adapter_DbTable#_authenticateCreateAuthResult()
	 */
	protected function _authenticateCreateAuthResult() {
		$resultIdentity = $this->getResultRowObject(null, 'password');

		$identity = new stdClass();
		$identity->user_id = $resultIdentity->user_id;
		$identity->username = $resultIdentity->username;
		$this->_setIdentityRoles($identity);

		return new Zend_Auth_Result($this->_authenticateResultInfo['code'], $identity,
				$this->_authenticateResultInfo['messages']);
	}

	protected function _setIdentityRoles($identity) {
		$mapper = new Bet_Model_UserMapper();
		$roles = $mapper->getUserGroupsById($identity->user_id);
		$identity->roles = $roles;
	}

}
?>